package xaj.com.test.demos.mapper;

import org.apache.ibatis.annotations.*;
import xaj.com.test.demos.model.UserInfo;

import java.util.List;

@Mapper
public interface UserInfoMapper {

    @ResultMap(value = {"BaseResult"})
    @Select("select * from userinfo")
    List<UserInfo> queryList() ;

    @Results(id = "BaseResult" , value = {
            @Result(column = "delete_flag", property = "deleteFlag"),
            @Result(column = "create_time" , property = "createTime"),
            @Result(column = "update_time" , property = "updateTime")
    })
    @Select("select * from userinfo")
    List<UserInfo> queryList3() ;

    @Select("select id, username , password ,age, gender, phone ," +
            "delete_flag as deleteFlag , " +
            "create_time as createTime , " +
            "update_time as updateTime " +
            " from userinfo")
    List<UserInfo> queryList2() ;

    @Options(useGeneratedKeys = true , keyProperty = "id")
    @Insert("insert into userinfo(username , password, age , gender) " +
            "values (#{username} , #{password} , #{age} , #{gender})" )
    Integer insertUserInfo(UserInfo userInfo);

    @Delete("delete from userinfo where username=#{username}")
    Integer deleteUserInfo(@Param("username") String username);

     @Update("update userinfo set phone=#{phone} where id=20")
    Integer updateUserInfo(@Param("phone")String phone);

}
